package com.beiming.libra.controller;

import javax.annotation.Resource;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.beiming.libra.common.page.PageResult;
import com.beiming.libra.domain.MenuInfo;
import com.beiming.libra.domain.dto.requestdto.CommonIdRequestDTO;
import com.beiming.libra.domain.dto.requestdto.MenuInfoRequestDTO;
import com.beiming.libra.service.MenuInfoService;
/**
 * 
 * @author weibo
 *
 */
@Controller
@Slf4j
@RequestMapping(value = "/menu")
public class MenuController {

  private static final Logger LOGGER = LoggerFactory.getLogger(MenuController.class);
  @Resource
  private MenuInfoService menuInfoService;

  /**
   * 新增菜单
   */
  @RequestMapping(value = "addMenuInfo", method = RequestMethod.POST)
  @ResponseBody
  public void addMenuInfo(@RequestBody @Valid MenuInfoRequestDTO menuInfoRequestDTO) {
    menuInfoService.insertMenuInfo(menuInfoRequestDTO);
  }

  /**
   * 获取菜单信息
   */
  @RequestMapping(value = "getMenuInfo", method = RequestMethod.POST)
  @ResponseBody
  public MenuInfo getMenuInfo(@RequestBody @Valid CommonIdRequestDTO commonIdRequestDTO) {
    return menuInfoService.getMenuInfo(commonIdRequestDTO.getId());
  }

  /**
   * 获取菜单列表
   */
  @RequestMapping(value = "listMenuInfo", method = RequestMethod.POST)
  @ResponseBody
  public PageResult<MenuInfo> listMenuInfo(@RequestBody MenuInfoRequestDTO menuInfoRequestDTO) {
    return menuInfoService.listMenuInfo(menuInfoRequestDTO);
  }

  /**
   * 更新菜单
   */
  @RequestMapping(value = "updateMenuInfo", method = RequestMethod.POST)
  @ResponseBody
  public void updateMenuInfo(@RequestBody @Valid MenuInfoRequestDTO menuInfoRequestDTO) {
    menuInfoService.updateMeunInfo(menuInfoRequestDTO);
  }

  /**
   * 删除菜单
   */
  @RequestMapping(value = "delateMenuInfo", method = RequestMethod.POST)
  @ResponseBody
  public void delateMenuInfo(@RequestBody @Valid CommonIdRequestDTO commonIdRequestDTO) {
    menuInfoService.deleteMenuInfo(commonIdRequestDTO.getId());
  }

  /**
   * 获取菜单树
   */
  @RequestMapping(value = "getMenusTree", method = RequestMethod.POST)
  @ResponseBody
  public void getMenusTree(@RequestBody MenuInfoRequestDTO menuInfoRequestDTO) {
    menuInfoService.getMenusTree();
  }
}
